/*
 * Statistics.java
 *
 * Created on January 4, 2008, 12:35 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package wisp.dataObjects;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.lang.Exception.*;
//import javax.servlet.jsp.*;
/**
 *
 * @author Nezie Santos
 */
public class Statistics {
    private dbConnection dbcon = new dbConnection();
    private int str, dex, cInt, vit, spr, atk, mAtk, def, res, mobility, statType;
    private double hpGR, mpGR, critRate, dRate, bRate, aRate, spd;
    private String characterName;
    
    
    /** Creates a new instance of Statistics */
    public Statistics(String cName, int sstr, int sdex, int scInt, int svit, int sspr, int satk, int smAtk, int sdef, int sres, double shpGR, double smpGR, double scritRate, double sdRate, double sbRate, double saRate, double sspd, int cmobility) {
        setStr(sstr);
        setDex(sdex); 
        setCInt(scInt);
        setVit(svit); 
        setSpr(sspr);
        setAtk(satk);
        setMAtk(smAtk); 
        setDef(sdef); 
        setRes(sres);
        setHpGR(shpGR);
        setMpGR(smpGR);
        setCritRate(scritRate);
        setDRate(sdRate);
        setBRate(sbRate); 
        setARate(saRate);
        setSpd(sspd);
        setCharacterName(cName);
        mobility = cmobility;
        setStatType(1);
        
    }

    public Statistics() {
    }
    
    public void viewStat (String cName){
        String query;
        ResultSet rs;
        PreparedStatement stmt;
                
        getDbcon().connect();
        query = "SELECT statType, str, dex, ints, vit, spr, atk, mAtk, def, res, hpGenRate, mpGenRate, critRate, dodgeRate, blockRate, accuracyRate, spd, characterName, mobility FROM Statistics WHERE characterName = ?";
        
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            stmt.setString(1, cName);
            rs = stmt.executeQuery();	
        
            while (rs.next()) 
            {	
                this.setStr(rs.getInt("str"));
                this.setDex(rs.getInt ("dex"));
                this.setCInt(rs.getInt("ints"));
                this.setVit(rs.getInt("vit")); 
                this.setSpr(rs.getInt("spr"));
                this.setAtk(rs.getInt("atk"));
                this.setMAtk(rs.getInt("mAtk"));
                this.setDef(rs.getInt("def"));
                this.setRes(rs.getInt("res"));
                this.setHpGR(rs.getDouble("hpGenRate"));
                this.setMpGR(rs.getDouble("mpGenRate"));                
                this.setCritRate(rs.getDouble("critRate"));
                this.setDRate(rs.getDouble("dodgeRate"));                
                this.setBRate(rs.getDouble("blockRate"));
                this.setARate(rs.getDouble("accuracyRate"));                
                this.setSpd(rs.getDouble("spd"));
                this.setCharacterName(rs.getString("characterName"));
                this.setMobility(rs.getInt("mobility"));
                this.setStatType((rs.getInt("statType")));
                System.out.println("statistics char str"+getStr());
             }
            rs.close(); 					
            stmt.close();
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
        finally {
            getDbcon().disconnect();
 
        }
    }
    
    public Vector viewAllMonsterStat (){
        String query;
        ResultSet rs;
        PreparedStatement stmt;
        
        Vector<Statistics> sList = new Vector<Statistics>();
                
        getDbcon().connect();
        query = "SELECT statType, str, dex, ints, vit, spr, atk, mAtk, def, res, hpGenRate, mpGenRate, critRate, dodgeRate, blockRate, accuracyRate, spd, characterName, mobility FROM Statistics WHERE statType = ?";
        
        try
        {
            stmt = getDbcon().con.prepareStatement(query);
            stmt.setInt(1, 0);
            rs = stmt.executeQuery();
            
            Statistics stat = null;
        
            while (rs.next()) 
            {	
                stat = new Statistics();
                stat.setStr(rs.getInt("str"));
                stat.setDex(rs.getInt ("dex"));
                stat.setCInt(rs.getInt("ints"));
                stat.setVit(rs.getInt("vit")); 
                stat.setSpr(rs.getInt("spr"));
                stat.setAtk(rs.getInt("atk"));
                stat.setMAtk(rs.getInt("mAtk"));
                stat.setDef(rs.getInt("def"));
                stat.setRes(rs.getInt("res"));
                stat.setHpGR(rs.getDouble("hpGenRate"));
                stat.setMpGR(rs.getDouble("mpGenRate"));                
                stat.setCritRate(rs.getDouble("critRate"));
                stat.setDRate(rs.getDouble("dodgeRate"));                
                stat.setBRate(rs.getDouble("blockRate"));
                stat.setARate(rs.getDouble("accuracyRate"));                
                stat.setSpd(rs.getDouble("spd"));
                stat.setCharacterName(rs.getString("characterName"));
                stat.setMobility(rs.getInt("mobility"));
                stat.setStatType((rs.getInt("statType")));
                System.out.println("statistics char str"+getStr());
                
                sList.add(stat);
             }
            rs.close(); 					
            stmt.close();
            return sList;
        } catch (Exception ex)
        {
            System.out.println(ex.getMessage());	       	
        }
        finally {
            getDbcon().disconnect();
 
        }
        return null;
    }
        
    public void addStatistics (Statistics s){
      						
        String query; 					
        ResultSet rs;
        PreparedStatement stmt;
       
        getDbcon().connect();
        query = "INSERT INTO Statistics (str,dex,ints,vit,spr,atk,mAtk,def,res,hpGenRate,mpGenRate,critRate,dodgeRate,blockRate,accuracyRate,spd,characterName,mobility,statType) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        try 
        {
            stmt = getDbcon().con.prepareStatement(query);
            System.out.println (s.getStr());
            stmt.setInt(1, s.getStr());
           System.out.println (s.getDex());
            stmt.setInt(2, s.getDex());
            System.out.println (s.getCInt());
           stmt.setInt(3, s.getCInt());
            System.out.println (s.getVit());
            stmt.setInt(4, s.getVit());
            System.out.println (s.getSpr());
            stmt.setInt(5, s.getSpr());
            System.out.println (s.getAtk());
            stmt.setInt(6, s.getAtk());
            System.out.println (s.getMAtk());
            stmt.setInt(7, s.getMAtk());
            System.out.println (s.getDef());
            stmt.setInt(8, s.getDef());
            System.out.println (s.getRes());
            stmt.setInt(9, s.getRes());
            System.out.println (s.getHpGR());
            stmt.setDouble(10, s.getHpGR());
            System.out.println (s.getMpGR());
            stmt.setDouble(11, s.getMpGR());
            System.out.println (s.getCritRate());
            stmt.setDouble(12, s.getCritRate());
            System.out.println(s.getDRate());
            stmt.setDouble(13, s.getDRate());
            System.out.println (s.getBRate());
            stmt.setDouble(14, s.getBRate());
            System.out.println (s.getARate());
            stmt.setDouble(15, s.getARate());
            System.out.println (s.getSpd());
            stmt.setDouble(16, s.getSpd());
            System.out.println (s.getCharacterName());
            stmt.setString(17, s.getCharacterName());
            System.out.println(s.getMobility());
            stmt.setInt(18, s.getMobility());
            stmt.setInt(19, s.getStatType());
            stmt.executeUpdate();	
            stmt.close();
            
        } catch (Exception ex) 
        {
            System.out.println(ex.getMessage());
        }
        getDbcon().disconnect();
        
    }
    
    public void editStat (String cName, String at, double dVal, int iVal) {
         						
        String query;
        PreparedStatement stmt;

        getDbcon().connect();
        
        if (at.equals("str"))
            query = "UPDATE Statistics SET str = ? WHERE characterName = ?";
        else if (at.equals("dex"))
            query = "UPDATE Statistics SET dex = ? WHERE characterName = ?";
        else if (at.equals("int"))
            query = "UPDATE Statistics SET ints = ? WHERE characterName = ?";
        else if (at.equals("vit"))
            query = "UPDATE Statistics SET vit = ? WHERE characterName = ?";
        else if (at.equals("spr"))
            query = "UPDATE Statistics SET spr = ? WHERE characterName = ?";
        else if (at.equals("hpGenRate"))
            query = "UPDATE Statistics SET hpGenRate = ? WHERE characterName = ?";
        else if (at.equals("mpGenRate"))
            query = "UPDATE Statistics SET mpGenRate = ? WHERE characterName = ?";
        else if (at.equals("atk"))
            query = "UPDATE Statistics SET atk = ? WHERE characterName = ?";
        else if (at.equals("mAtk"))
            query = "UPDATE Statistics SET mAtk = ? WHERE characterName = ?";
        else if (at.equals("def"))
            query = "UPDATE Statistics SET def = ? WHERE characterName = ?";
        else if (at.equals("res"))
            query = "UPDATE Statistics SET res = ? WHERE characterName = ?";
        else if (at.equals("critRate"))
            query = "UPDATE Statistics SET critRate = ? WHERE characterName = ?";
        else if (at.equals("dodgeRate"))
            query = "UPDATE Statistics SET dodgeRate = ? WHERE characterName = ?";
        else if (at.equals("blockRate"))
            query = "UPDATE Statistics SET blockRate = ? WHERE characterName = ?";
        else if (at.equals("accuracyRate"))
            query = "UPDATE Statistics SET accuracyRate= ? WHERE characterName = ?";
        else if (at.equals("mobility"))
            query = "UPDATE Statistics SET mobility = ? WHERE characterName = ?";
        else if (at.equals("statType"))
            query = "UPDATE Statistics SET statType = ? WHERE characterName = ?";
        else 
            query = "UPDATE Statistics SET speed = ? WHERE characterName = ?";
        
        try 
        {
             
            stmt = getDbcon().con.prepareStatement(query);
            
            if (at.equals("hpGenRate")|| at.equals("mpGenRate")|| at.equals("critRate")|| at.equals("dodgeRate")|| at.equals("blockRate")|| at.equals("accuracyRate")|| at.equals("spd"))
                stmt.setDouble(1, dVal);
            else
                stmt.setInt(1, iVal);
            
            stmt.setString(2, cName);
            stmt.executeUpdate();	
            stmt.close();					
        } catch (Exception ex) 
        {
            System.out.println(ex.getMessage());	       	
        }
        getDbcon().disconnect();
     }

    public dbConnection getDbcon() {
        return dbcon;
    }

    public void setDbcon(dbConnection dbcon) {
        this.dbcon = dbcon;
    }

    public int getStr() {
        return str;
    }

    public void setStr(int str) {
        this.str = str;
    }

    public int getDex() {
        return dex;
    }

    public void setDex(int dex) {
        this.dex = dex;
    }

    public int getCInt() {
        return cInt;
    }

    public void setCInt(int cInt) {
        this.cInt = cInt;
    }

    public int getVit() {
        return vit;
    }

    public void setVit(int vit) {
        this.vit = vit;
    }

    public int getSpr() {
        return spr;
    }

    public void setSpr(int spr) {
        this.spr = spr;
    }

    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }

    public int getMAtk() {
        return mAtk;
    }

    public void setMAtk(int mAtk) {
        this.mAtk = mAtk;
    }

    public int getDef() {
        return def;
    }

    public void setDef(int def) {
        this.def = def;
    }

    public int getRes() {
        return res;
    }

    public void setRes(int res) {
        this.res = res;
    }

    public double getHpGR() {
        return hpGR;
    }

    public void setHpGR(double hpGR) {
        this.hpGR = hpGR;
    }

    public double getMpGR() {
        return mpGR;
    }

    public void setMpGR(double mpGR) {
        this.mpGR = mpGR;
    }

    public double getCritRate() {
        return critRate;
    }

    public void setCritRate(double critRate) {
        this.critRate = critRate;
    }

    public double getDRate() {
        return dRate;
    }

    public void setDRate(double dRate) {
        this.dRate = dRate;
    }

    public double getBRate() {
        return bRate;
    }

    public void setBRate(double bRate) {
        this.bRate = bRate;
    }

    public double getARate() {
        return aRate;
    }

    public void setARate(double aRate) {
        this.aRate = aRate;
    }

    public double getSpd() {
        return spd;
    }

    public void setSpd(double spd) {
        this.spd = spd;
    }

    public String getCharacterName() {
        return characterName;
    }

    public void setCharacterName(String characterName) {
        this.characterName = characterName;
    }

    public int getMobility() {
        return mobility;
    }

    public void setMobility(int mobility) {
        this.mobility = mobility;
    }

    public int getStatType() {
        return statType;
    }

    public void setStatType(int statType) {
        this.statType = statType;
    }

   

}
